var e = require;
var t = module;
var o = exports;
var n;
function i(e, t) {
    return (i =
        Object.setPrototypeOf ||
        function (e, t) {
            return (e.__proto__ = t), e;
        })(e, t);
}
(o.__esModule = !0), (o.default = void 0);
var a = (function (e) {
    var t, o;
    function n() {
        return e.call(this) || this;
    }
    (o = e), ((t = n).prototype = Object.create(o.prototype)), (t.prototype.constructor = t), i(t, o);
    var a = n.prototype;
    return (
        (a.init = function () {
            (this.env = window.qg),
                (this.info = (window.lplatform && lplatform.systemInfo) || this.env.getSystemInfoSync()),
                (this.bh = lplatform.cparam.bannerHeight || 170),
                (this.bw = lplatform.cparam.bannerWidth || Math.min(this.info.windowWidth, (16 * this.bh) / 9)),
                this.env.setKeepScreenOn &&
                    this.env.setKeepScreenOn({
                        keepScreenOn: !0,
                        success: function success() {
                            console.log("handling success");
                        },
                        fail: function fail(e, t) {
                            console.log("handling fail, code = " + t);
                        }
                    });
        }),
        (a.initAD = function () {
            this.createRewardedVideo(!1),
                setTimeout(
                    function () {
                        this.createMoreGamePortal(!1, !0);
                    }.bind(this),
                    1e4
                );
        }),
        (a.loadBanner = function (e) {
            this.hideBanner(!0),
                this.bannerAd ||
                    ((this.btop = 0),
                    lplatform.cparam.bannerOnBottom && (this.btop = this.info.windowHeight - this.bh),
                    lplatform.plog(
                        "loadBanner this.bh:" +
                            this.bh +
                            " this.btop:" +
                            this.btop +
                            " this.bw:" +
                            this.bw +
                            " lplatform.cparam.bannerID:" +
                            lplatform.cparam.bannerID
                    ),
                    (this.bannerAd = this.env.createBannerAd({
                        posId: lplatform.cparam.bannerID,
                        adIntervals: 30,
                        style: {}
                    })),
                    this.bannerAd.onLoad(this.onBannerLoad.bind(this)),
                    this.bannerAd.onError(this.onBannerError.bind(this)),
                    this.bannerAd.onSize(this.onBannerResize.bind(this))),
                (this.bannerAutoShow = e),
                e && this.bannerAd.show();
        }),
        (a.showBanner = function () {
            this.loadBanner(!0);
        }),
        (a.showVivoInterstitial = function () {
            var e = this,
                t = qg.createInterstitialAd({posId: lplatform.cparam.interstitialID});
            t.onError(function (e) {
                console.log("插屏广告加载失败", e);
            }),
                t
                    .show()
                    .then(function () {
                        console.log("插屏广告展示完成"), e.customAd && e.customAd.destroy();
                    })
                    .catch(function (e) {
                        console.log("插屏广告展示失败", JSON.stringify(e));
                    });
        }),
        (a.loadInterstitial = function (e) {
            var t = this;
            this.customAd && this.customAd.destroy();
            var o = this.env.createCustomAd({
                posId: lplatform.cparam.nativeID[0],
                style: {left: (this.info.windowWidth - 1080) / 2, top: (this.info.windowHeight - 720) / 2}
            });
            o.onLoad(function () {}.bind(this)),
                o.onError(
                    function () {
                        t.showVivoInterstitial();
                    }.bind(this)
                ),
                o.onClose(function () {}.bind(this)),
                (this.customAd = o),
                e && this.customAd.show();
        }),
        (a.showInterstitial = function () {
            this.loadInterstitial(!0);
        }),
        (a.hideInterstitial = function () {
            this.customAd && (this.customAd.destroy(), (this.customAd = null));
        }),
        (a.createMoreGameBanner = function () {
            lplatform.cparam.moreGameBannerId &&
                (this.moreGameBanner ||
                    (console.log("createBoxBannerAd:" + lplatform.cparam.moreGameBannerId),
                    (this.moreGameBanner = this.env.createBoxBannerAd({posId: lplatform.cparam.moreGameBannerId})),
                    this.moreGameBanner.onError(function (e, t) {
                        lplatform.plog("moreGameBanner onError:" + JSON.stringify(e) + " " + JSON.stringify(t));
                    })),
                console.log("moreGameBanner show"),
                this.moreGameBanner
                    .show()
                    .then(function () {
                        console.log("moreGameBanner show success");
                    })
                    .catch(function (e) {
                        console.log("moreGameBanner show fail with:" + e.errCode + "," + e.errMsg);
                    }),
                lplatform.cparam.moreGameBannerAutoCloseTime > 0 &&
                    setTimeout(
                        function () {
                            this.moreGameBanner.hide();
                        }.bind(this),
                        lplatform.cparam.moreGameBannerAutoCloseTime
                    ));
        }),
        (a.createMoreGamePortal = function (e, t) {
            if ((void 0 === e && (e = !1), void 0 === t && (t = !1), "function" == typeof this.env.createBoxPortalAd)) {
                if ((e && this.moreGamePortal, !this.moreGamePortal)) {
                    var o = Math.floor(Math.random() * lplatform.cparam.spreadBoxID.length),
                        n = lplatform.cparam.spreadBoxID[o];
                    lplatform.plog("createMoreGamePortal:" + n),
                        (this.moreGamePortal = this.env.createBoxPortalAd({
                            posId: n,
                            image: lplatform.cparam.moreGamePortalIconUrl,
                            marginTop: lplatform.cparam.moreGamePortalMarginTop
                        }));
                }
                t &&
                    this.moreGamePortal
                        .show()
                        .then(function () {})
                        .catch(function (e) {
                            lplatform.plog("createMoreGamePortal show fail:" + JSON.stringify(e));
                        });
            }
        }),
        (a.createRewardedVideo = function (e) {
            lplatform.cparam.rewardedVideoID &&
                (this.rewardedVideoAd ||
                    "function" != typeof this.env.createRewardedVideoAd ||
                    ((this.rewardedVideoAd = this.env.createRewardedVideoAd({posId: lplatform.cparam.rewardedVideoID})),
                    this.rewardedVideoAd.onError(this.onRewardedVideoError.bind(this)),
                    this.rewardedVideoAd.onClose(this.onRewardedVideoClose.bind(this)),
                    this.rewardedVideoAd.onLoad(this.onRewardedVideoLoad.bind(this))),
                e && this.showRewardedVideo(window.vcb));
        }),
        (a.showRewardedVideo = function (e) {
            var t = this;
            e && (window.vcb = e),
                lplatform.pauseGame(),
                this.rewardedVideoAd
                    ? (lplatform.plog("showRewardedVideo this.rewardedVideoIsLoaded:" + this.rewardedVideoIsLoaded),
                      this.rewardedVideoAd
                          .show()
                          .then(function () {
                              lplatform.plog("oppo的rewardedVideo.show().then()在视频结束时才调用，shit.");
                          })
                          .catch(function (e) {
                              lplatform.plog("showRewardedVideo catch:" + JSON.stringify(e)),
                                  t.rewardedVideoAd
                                      .load()
                                      .then(function () {
                                          t.rewardedVideoAd.show();
                                      })
                                      .catch(function () {
                                          t.loadRewardedVideo(!1);
                                      });
                          }))
                    : this.createRewardedVideo(!0);
        }),
        (a.onRewardedVideoError = function (t, o) {
            e.prototype.onRewardedVideoError.call(this, t, o),
                this.env.showToast({message: "广告展示失败，请稍后重试！"}),
                lplatform.resumeGame();
        }),
        (a.onRewardedVideoClose = function (t) {
            e.prototype.onRewardedVideoClose.call(this, t), lplatform.resumeGame();
        }),
        (a.goToGameOrGameList = function () {
            lplatform.plog("vivoGame未实现 goToGameOrGameList");
        }),
        (a.showFavoriteGuide = function () {
            var e = this;
            lplatform.cparam.closeBtnScale,
                e.env.hasShortcutInstalled({
                    success: function success(t) {
                        0 == t &&
                            e.env.installShortcut({
                                success: function success() {},
                                fail: function fail() {},
                                complete: function complete() {}
                            });
                    },
                    fail: function fail() {},
                    complete: function complete() {}
                });
        }),
        (a.canRecord = function () {
            return !1;
        }),
        (a.canShareRecord = function () {
            return !1;
        }),
        (a.startRecord = function () {}),
        (a.pauseRecord = function () {}),
        (a.resumeRecord = function () {}),
        (a.stopRecord = function () {}),
        (a.shareRecord = function (e, t) {
            t && t();
        }),
        (a.resetRecord = function () {}),
        (a.httpRequest = function (e, t, o, n, i, a, r) {
            void 0 === r && (r = "text"),
                this.env.request({
                    url: e,
                    data: i,
                    header: a,
                    timeout: o,
                    method: n,
                    dataType: r,
                    success: function success(e) {
                        t(null, e.data, e.data);
                    },
                    fail: function fail(e) {
                        t(e, null, null);
                    }
                });
        }),
        n
    );
})(((n = e("POppo")) && n.__esModule ? n : {default: n}).default);
(o.default = a), (t.exports = o.default);
